package com.qf.bank.userinfoprovider.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.bank.userinfoapi.po.UserInfo;
import com.qf.bank.userinfoprovider.service.IUserInfoService;
import com.sun.media.jfxmedia.logging.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author q
 * @since 2019-12-06
 */
@Slf4j
@RestController
public class UserInfoController {
    @Autowired
    IUserInfoService userInfoService;
//    @RequestMapping(value = "",method = RequestMethod.GET)
//    public IPage<UserInfo> page(@RequestBody UserInfo userInfo){
//        return userInfoService.page((IPage<UserInfo>) userInfo);
//    }
//@RequestMapping(value = "/", method = RequestMethod.GET)
//public IPage<UserInfo> page(@RequestParam int current, @RequestParam int size) {
//    IPage<UserInfo> page = userInfoService.page(new Page<>(current, size));
//    return page;
//}
//    查詢所有用戶信息
    @RequestMapping(value = "all/findAll",method = RequestMethod.GET)
    public List findAll(){
        List<UserInfo> list = userInfoService.list();
        return list;
    }
    @RequestMapping(value = "/{userinfoId}",method = RequestMethod.GET)
    public UserInfo findOne(@PathVariable(value = "userinfoId") int userinfoId){

        UserInfo userInfo = userInfoService.getById(userinfoId);
        return userInfo;
    }
//    刪除用戶信息
    @RequestMapping(value = "/{userinfoId}",method = RequestMethod.DELETE)
    public boolean deleteById(@PathVariable(value = "userinfoId")  int userinfoId){
        boolean byId = userInfoService.removeById(userinfoId);
        return byId;
    }
    //xiu修改
    @RequestMapping(value = "/upuserinfo",method = RequestMethod.PUT)
    public boolean update(@RequestBody UserInfo userInfo){
        userInfoService.save(userInfo);
        return true;
    }
    //增加
    @RequestMapping(value = "/insertuserinfo",method = RequestMethod.POST)
    public UserInfo insert(@RequestBody UserInfo userInfo){
        userInfoService.save(userInfo);
        return userInfo;
    }

}
